#!/usr/bin/python3.8.9
# -*- coding: utf-8 -*-

# @Author  : Tina Yu
# @Time    : 2021-6-20 23:19
'''
函数
1. 位置实参
2. 关键字实参
3. 默认值
'''
import pytest


def display_message():
    print('本章学习的是函数-传递实参！')


def favorite_book(book_name):
    print(f'我最喜欢的书是：{book_name.title()}')


def describe_pet(pet_name, animal_type='dog'):
    print(f'\nI have a {animal_type}')
    print(f"It's name is {pet_name}")


display_message()
favorite_book('python 从入门到实践')
describe_pet('small_white')


def city_country(city_name, country_name):
    city_country = f'{country_name}, {city_name.title()}'
    return city_country


@pytest.mark.parametrize('country, city', [('China', 'shanghai'), ('China', 'shenzhen'), ('Santiago', 'chile')])
def test_city_country(city, country):
    result = city_country(city, country)
    print(result)


# 传递列表
def greet_users(names):
    for name in names:
        msg = f"Hello,{name.title()}!"
        print(msg)


def test_greet_users():
    user_names = ['yuhuifei', 'yukexin', 'maozhuxi']
    greet_users(user_names)


# 在函数中修改列表
def test_change_list():
    unprinted_designs = ['phone case', 'robot pendant', 'dodecahedron']
    completed_models = []
    # 打印完unprinted_designs就为空了
    # print_current_design(unprinted_designs, completed_models)

    # 打印完unprinted_designs还保留原样
    print_current_design(unprinted_designs[:], completed_models)
    show_printed_designs(completed_models)
    print(unprinted_designs)


def print_current_design(unprinted_designs, completed_models):
    while unprinted_designs:
        current_design = unprinted_designs.pop()
        print(f"Printing model:{current_design}")
        completed_models.append(current_design)


def show_printed_designs(completed_models):
    print("\nThe following models have been printed:")
    for completed_model in completed_models:
        print(completed_model)


# 练习 8-9：
'''
1. 创建一个列表，包含一系列文本消息，将该列表传给一个函数，该函数会打印每一条消息。
2. 新增一函数send_msg()，将每条消息打印出来，并移到一个名为sent_msgs列表中，最后打印两个列表
'''


def show_msg(msg_list):
    for current_msg in msg_list:
        print(current_msg)


def get_msg(num):
    msgs = []
    for i in range(num):
        current_msg = input("请输入要发送的消息：")
        msgs.append(current_msg)
    return msgs


def send_msg(msgs, sent_msgs):
    while msgs:
        current_msg = msgs.pop()
        print(current_msg)
        sent_msgs.append(current_msg)
    return sent_msgs


if __name__ == '__main__':
    msgs = get_msg(3)
    sent_msgs = []
    send_msg(msgs[:], sent_msgs)
    print("*************需要发送的消息清单*************")
    show_msg(msgs);
    print("*************已经发送的消息清单*************")
    show_msg(sent_msgs)


# 传递任意数量的参数[*args]
# def make_pizza(size, *toppings):
#     # 打印顾客点的所有配料
#     print(f"\nMaking a {size}-inch pizza with the following toppings:")
#     for topping in toppings:
#         print(f'-{topping}')


def test_make_pizza():
    make_pizza(11, 'pepperoni')
    make_pizza(7, 'mushrooms', 'green peppers', 'extra cheese')


# 使用任意数量的关键字实参[**kwargs]
def build_profile(first, last, **user_info):
    user_info['first_name'] = first
    user_info['last_name'] = last
    return user_info


def test_build_profile():
    user_profile = build_profile('yu', 'huifei', location='shenzhen', field='computer', weight='102')
    print(user_profile)


# 练习8-12【三明治】
'''
1. 编写一个函数，接收顾客需要在三明治中添加的食材。这个函数只有一个形参，并打印一条消息，对顾客的三明治进行概述。
'''


def make_sandwich(items):
    print("该顾客需要的食材如下：")
    for item in items:
        print(item)


def test_make_sandwich():
    make_sandwich('yi', 'er', 'san', 'si')
    make_sandwich('1', '2', '3', '4', '5')


# 练习8-14【汽车】
'''
编写函数，将汽车信息存储在字典中。函数接收制造商和型号，且接收任意数量的关键字实参。
'''


def test_make_car():
    car = make_car('subaru', 'outback', color='black', tow_package=True)
    print(car)


# 使用as给函数指定别名

